<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
    <div class="box">
        <div class="left">
            <img src="img/404/login.jpg" alt="">
            <div class="logo">
                <a href="index.html"><img src="img/404/logo.png" alt=""></a>
             </div>
        </div>
        <div class="right">
            <div class="login">
                <p class="title">登录</p>
                <input type="text" placeholder="手机*" id="phone" onblur="checkPhone()">
                <span id="u_phone"></span>
                <input type="password" placeholder="密码*" id="pwd" onblur="checkpwd()">
                <span id="u_pwd"></span>
                <a class="dl" id="s">登录</a>
                <a href="zhuce.html" class="zc">注册DJI账号</a>
                <p class="sf">或使用第三方账号登录</p>
                <a href="#" class="dl wei">微信</a>
            </div>
        </div>
    </div>
</body>
<script>
    function checkPhone(){
        var phone=document.getElementById("phone").value;
        var uphone=document.getElementById("u_phone");
        uphone.innerHTML="";
        var regphone=/^1[3-9]\d{9}$/;
        if(!regphone.test(phone)==true){
            uphone.innerHTML="请输入正确的手机号"
            return false;
        }else{
            uphone.innerHTML="";
            return true;
        } 
    }
    function checkpwd(){
        var pwd=document.getElementById("pwd").value;
        var upwd=document.getElementById("u_pwd");
        upwd.innerHTML="";
        var regpwd=/^[a-zA-Z0-9]{6,10}$/;
        if(!regpwd.test(pwd)==true){
            upwd.innerHTML="密码或用户名不正确"
            return false;
        }else{
            upwd.innerHTML="";
            return;
        }
    }
		s.onclick=function(){
				var uphone=phone.value
				var upwd=pwd.value
				var xhr=new XMLHttpRequest();
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4 && xhr.status==200){
						var result=xhr.responseText;
                        var user=result
						if(result!=null){
							location.href="index.html?name="+user;
						}else{
							alert("用户名或密码错误")
						}
					}
				}
				var url="http://127.0.0.1:8080/user/login"
				xhr.open("post",url,true)
				var formdata="uphone="+uphone+"&upwd="+upwd
				xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
				xhr.send(formdata)
			}
</script>
</html>